<template>
  <div>
    <div class="head">
      <img
        src="@/assets/css/images/cooperate.png"
        alt=""
        style=" width: 45px;height: 45px;vertical-align:middle; border-radius:5px"
      />
      <b> 与我协作</b>
      <br /><br />
      <el-button
        type="primary"
        @click="teamDialog = true"
        style="margin-left:10px"
        >新建协作组</el-button
      >
    </div>
    <br />
    <el-card style="border-radius:10px;height:100vh">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="name" label="全部协作组" sortable>
          <template slot-scope="scope" class="rowText">
            <div class="icon">
              <svg class="icons" aria-hidden="true">
                <use v-bind:xlink:href="scope.row.icon"></use>
              </svg>
            </div>
            <div class="text">
              <b
                class="rowname"
                @click="goDetailPage(scope.row.name)"
                style="margin-left:15px"
              >
                {{ scope.row.name }}</b
              >
              <br />
              <small style="margin-left:15px">
                协作组成员人数：{{ scope.row.member }}人</small
              >
            </div>
          </template>
        </el-table-column>
        <el-table-column width="200">
          <template slot-scope="scope">
            <el-tooltip
              class="item"
              effect="dark"
              :content="scope.row.introduction"
              placement="top"
            >
              <el-button
                circle
                type="info"
                icon="el-icon-info"
                @click="showInfo"
              >
              </el-button>
            </el-tooltip>
            <el-button
              type="danger"
              plain
              icon="el-icon-close"
              @click.native="deleteRow(scope.row)"
              circle
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-dialog
      title="新建协作组"
      :visible.sync="teamDialog"
      :close-on-click-modal="false"
    >
      <el-form :model="form" ref="form">
        <el-form-item label="创建人：" :label-width="formLabelWidth">
          <el-input placeholder="当前用户" disabled> </el-input>
        </el-form-item>
        <el-form-item label="协作组名称：" :label-width="formLabelWidth">
          <el-input v-model="form.name" placeholder="请输入名称"> </el-input>
        </el-form-item>
        <el-form-item label="协作组简介：" :label-width="formLabelWidth">
          <el-input
            v-model="form.introduction"
            type="textarea"
            placeholder="请输入协作组简介信息"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="协作组头像：">
          <!-- mark用来确定方向的指向 -->
          <el-select
            style="width: 10%;"
            placeholder="请选择"
            v-model="form.icon"
          >
            <el-option
              v-for="item in directionOption"
              :key="item.value"
              :value="item.value"
            >
              <b style="margin-top:-30px;margin-right:5px">{{ item.value }}</b>
              <svg class="icons" aria-hidden="true">
                <use v-bind:xlink:href="item.label"></use>
              </svg>
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          type="info"
          @click="teamDialog = false"
          round
          plain
          style="margin-right:15px"
          >取消</el-button
        >
        <el-button
          type="primary"
          @click="createNewTeam"
          round
          plain
          style="margin-left:15px"
          >完成</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [
        {
          name: "垃圾小队",
          introduction: "图吧垃圾佬",
          icon: "#icon-a-zhifushoutiaoshoujufapiao",
          member: 5,
          owner: "",
        },
        {
          name: "教学资源管理平台开发小组",
          introduction: "中原工学院计算机学院教学资源管理系统毕业设计小组",
          icon: "#icon-a-shuzhishijiaoyu",
          member: 7,
        },
        {
          name: "小虎队",
          introduction: "",
          icon: "#icon-a-taidengxuexi",
          member: 3,
        },
        {
          name: "公告栏",
          introduction: "",
          icon: "#icon-a-jiangtaiyanjiangchuanshouxuexi",
          member: 1,
        },
        {
          name: "在线客服",
          introduction: "",
          icon: "#icon-a-shuzhishijiaoyu",
          member: 1,
        },
        {
          name: "消息反馈",
          introduction: "",
          icon: "#icon-a-Marketinggouwuyingxiaoshichang",
          member: 1,
        },
      ],
      form: {
        name: "",
        owner: "admin",
        introduction: "",
        icon: "",
        icon: "",
      },
      founder: "",
      directionOption: [
        {
          label: "#icon-gongjiaochechezhanzhantai",
          value: "头像1",
        },
        {
          label: "#icon-a-jiangtaiyanjiangchuanshouxuexi",
          value: "头像2",
        },
        {
          label: "#icon-a-shuzhishijiaoyu",
          value: "头像3",
        },
        {
          label: "#icon-a-taidengxuexi",
          value: "头像4",
        },
        {
          label: "#icon-a-shuqianshumulu",
          value: "头像5",
        },
        {
          label: "#icon-a-zhifushoutiaoshoujufapiao",
          value: "头像6",
        },
        {
          label: "#icon-a-Marketinggouwuyingxiaoshichang",
          value: "头像7",
        },
      ],

      teamDialog: false,
    };
  },
  created() {
    this.getTeamList();
  },
  methods: {
    //新建协作组
    createNewTeam() {
      var params = this.form;
      console.log(this.form);
      this.$http
        .post("http://192.168.43.79:8080/group/add", params)
        .then((res) => {
          this.teamDialog = false;
          if (res.data.code == "200") {
            this.$message.success("获取协作组成功！");
          } else {
            this.$message.error("获取协作组失败！");
          }
        });

      this.getTeamList();
    },
    //获取协作组列表
    // TODO根据用户
    getTeamList() {
      this.$http.get("http://192.168.43.79:8080/group/list").then((res) => {
        console.log(res);
        this.tableData = res.data.data;
        if (res.data.code !== "200") {
          this.$message.error("操作失败！");
        } else {
          this.$message.success("操作成功！");
        }
      });
    },
    goDetailPage(name) {
      var { href } = this.$router.resolve({
        name: "teamDetail",
      });
      localStorage.setItem("teamName", name);
      window.open(href);
    },
    // 退出协作组
    deleteRow(index) {
      console.log(index);
      this.$http.post("http://192.168.43.79:8080/group/delete",index)
      this.$confirm("是否退出该协作组?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.total--;
          this.tableData.splice(index, 1);
          this.$message({
            type: "success",
            message: "已退出!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
  },
};
</script>

<style lang="less" scoped>
.fileimg {
  width: 45px;
  height: 45px;
}
.icon,
.text {
  display: table-cell;
  vertical-align: middle;
  margin-right: 5px;
  cursor: pointer;
}
.icons {
  width: 35px;
  height: 32px;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}
</style>
